<template>
  <div>

    <van-nav-bar
        title="聊天"
        fixed
    />

    <div style="padding: 7vh 0 7vh 0">
      <van-pull-refresh v-model="userPage.refresh" @refresh="onRefreshUser()">
        <user :user="userPage.userList" :is-chart="true" :is-follow="true"/>
      </van-pull-refresh>
    </div>
    <!-- 底部导航条 -->
    <tabbar/>
  </div>
</template>

<script>
import Tabbar from "../components/Tabbar";
import User from "../components/User";
import {Toast} from "vant";

export default {
  components: {Tabbar, User},
  data() {
    return {
      userPage: {
        userList: [{
          name: "",
          id: "",
          account: "",
          img: "",
          isFollowed: false,
        }],
        refresh: true,
      },
    };
  },
  mounted() {
    this.listUser();

  },
  methods: {

    onRefreshUser() {
      setTimeout(() => {
        Toast("刷新成功");
        this.userPage.refresh = false;
        this.listUser();
      }, 1000);
    },
    listUser() {
      this.http.get("/api/zyx/user/follow/list").then((res) => {
        // 请求到数据存放到本地
        this.userPage.userList = [];
        for (let i in res.data.data) {
          this.userPage.userList.push({
            id: res.data.data[i].id,
            name: res.data.data[i].name,
            account: res.data.data[i].account,
            isFollowed: true,
            img: res.data.data[i].profileImg ? res.data.data[i].profileImg : "404.jpg"
          })
        }
      });
    }
  }
};
</script>

<style scoped>
</style>
